package lesson_four;

public class Lists1Exercises {
    /**
     * 返回一个与 L 相同的 lesson_four.IntList，但每个元素递增 x。L不允许更改。
     */
    public static IntList incrList(IntList L, int x) {
        /* Your code here. */
        IntList Q = new IntList(0, null);
        if (L == null) {
            return null;
        }
        Q.first = L.first + x;
        Q.rest = dincrList(L.rest, x);
        return Q;
    }

    /**
     * 返回一个与 L 相同的 lesson_four.IntList，但每个元素递增 x。不允许使用“new”关键字。
     */
    public static IntList dincrList(IntList L, int x) {
        /* Your code here. */
        if (L == null) {
            return null;
        }
        L.first = L.first + x;
        L.rest = dincrList(L.rest, x);
        return L;
    }

    public static void main(String[] args) {
        IntList L = new IntList(5, null);
        L.rest = new IntList(7, null);
        L.rest.rest = new IntList(9, null);

        System.out.println(L.size());
        System.out.println(L.iterativeSize());

        // Test your answers by uncommenting. Or copy and paste the code for incrList and dincrList into lesson_four.IntList.java and run it in the visualizer.
        System.out.println(L.get(1));
        System.out.println(incrList(L, 3));
        System.out.println(dincrList(L, 3));
    }
}
